package com.mareas.web.jsf.view;

import java.io.Serializable;
import java.util.List;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.RequestScoped;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.mareas.web.model.Buque;
import com.mareas.web.service.BuqueService;

@Component("listBuqueView")
@ManagedBean
@RequestScoped 
public class ListBuqueView implements Serializable {

	/**
	 *
	 */
	private static final long serialVersionUID = -2414982654514242280L;

	@ManagedProperty(value = "#{buqueService}")
	@Autowired
	private BuqueService buqueService;

	private int page = 1;
	private int currentBuqueIndex;
	private Buque editedBuque;
	private Buque deletedBuque;

	public ListBuqueView() {
		super();
	}

	public Buque getNewBuque() {
		return buqueService.newBuque();
	}

	public void remove() {
		buqueService.remove(deletedBuque);
	}

	public void store() {
		if(editedBuque.getBuqueImo() != null) {
			buqueService.update(editedBuque);
		}else {
			buqueService.persist(editedBuque);
		}
		
	}

	public List<Buque> getBuques() {
		return buqueService.getBuques();
	}

	public BuqueService getBuqueService() {
		return buqueService;
	}

	public void setBuqueService(BuqueService buqueService) {
		this.buqueService = buqueService;
	}

	public Buque getEditedBuque() {
		return editedBuque;
	}

	public void setEditedBuque(Buque editedBuque) {
		this.editedBuque = editedBuque;
	}

	public int getPage() {
		return page;
	}

	public void setPage(int page) {
		this.page = page;
	}

	public int getCurrentBuqueIndex() {
		return currentBuqueIndex;
	}

	public void setCurrentBuqueIndex(int currentBuqueIndex) {
		this.currentBuqueIndex = currentBuqueIndex;
	}

	public Buque getDeletedBuque() {
		return deletedBuque;
	}

	public void setDeletedBuque(Buque deletedBuque) {
		this.deletedBuque = deletedBuque;
	}

}
